//
//  XCHPlayObject.swift
//  视频悬浮框Swift
//
//  Created by 解楚豪 on 2018/9/18.
//  Copyright © 2018年 xch. All rights reserved.
//

import UIKit
import Foundation
import AVKit
import AVFoundation

class XCHPlayObject: NSObject {

    //单利
    static let instance:XCHPlayObject = XCHPlayObject()
    class func shareInstance() -> XCHPlayObject {
        return instance
    }
    
    //网址
    var url:String?
    var videoUrl:String{
        set{
            url = newValue
            
            if url != newUrl {
                
            }
        }
        get{
            return url!
        }
    }
    private var  newUrl:String? = nil
    
    //MARK: -------------set-----------------------
    
    var frame:CGRect {
        set{
//            _frame = newValue
            //视频显示范围
            playerLayer.frame = newValue
        }
        get{
            return .zero
        }
    }
    
    //MARK: --------------------------方法---------------------
    //视频暂停
    func videoPause() {
        player.pause()
    }
    //视频播放
    func videoPlay() {
        player.play()
    }
    //界面添加显示
    func supperAddView(supView:UIView) {
        
        supView.layer.addSublayer(playerLayer)
    }
    
    //MARK: ----------------懒加载----------------------
    lazy var player : AVPlayer = {
        let tempPlayer = AVPlayer.init(url: URL.init(string: videoUrl)!)
        
        return tempPlayer
    }()
   lazy var playerLayer: AVPlayerLayer = {
        let tempPlayerLayer = AVPlayerLayer.init(player: player)
        return tempPlayerLayer
    }()
    
}
